package com.zhika.zishi.fragments.set;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zhika.zishi.R;
import com.zhika.zishi.customview.TitleView;
import com.zhika.zishi.interfaces.TitleInterface;

/**
 * Created by shi-02 on 2015/4/18.
 * 在设置中，隐私与安全、提醒与通知共用一个Activity
 */
public class SecureRemindFragment extends Fragment implements View.OnClickListener{

    private TitleView titleView;

    private TextView firstText;
    private ImageView firstImageView;

    private TextView secondText;
    private ImageView secondImageView;

    private TextView thirdText;
    private ImageView thirdImageView;

    private RelativeLayout firstLayout;

    //标记是什么类型：隐私与安全、提醒与通知
    private String type = "";


    private View view;

    private Context context;


    public interface OnSecureRemindInterface{

        //移除此fragment
        public void remoteSecureRemindFragment();

        //更改密码
        public void modifyPassword();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.secure_remind_setting_layout,container,false);

        initView();

        return view;
    }

    private void initView(){

        context = getActivity();

        titleView = (TitleView) view.findViewById(R.id.secure_remind_setting_title_view);
        titleView.setTitleViewInterface(new TitleInterface() {
            @Override
            public void leftTitleListener() {
                ((OnSecureRemindInterface)context).remoteSecureRemindFragment();
            }

            @Override
            public void middleTitleListener() {

            }

            @Override
            public void rightTitleListener() {

            }
        });
        titleView.hideRightButton();
        titleView.setLeftButtonText("返回");

        firstImageView = (ImageView) view.findViewById(R.id.secure_remind_setting_first_image_view);
        firstText = (TextView) view.findViewById(R.id.secure_remind_setting_first_text);

        secondImageView = (ImageView) view.findViewById(R.id.secure_remind_setting_second_image_view);
        secondText = (TextView) view.findViewById(R.id.secure_remind_setting_second_text);

        thirdImageView = (ImageView) view.findViewById(R.id.secure_remind_setting_third_image_view);
        thirdText = (TextView) view.findViewById(R.id.secure_remind_setting_third_text);

        Bundle bundle = getArguments();
        if (bundle!=null){
            type = bundle.getString("secure_remind");
            if (type.equals("secure")){
                titleView.setMiddleRowText("隐私与安全");
            }else {
                titleView.setMiddleRowText("提醒与通知");
                firstText.setText("每日精选推送");
                secondText.setText("资势活动通知");
                thirdText.setText("攻略动态提醒");
            }

        }
        firstLayout =(RelativeLayout) view.findViewById(R.id.secure_remind_setting_first_layout);
        firstLayout.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (context instanceof OnSecureRemindInterface){
            switch (v.getId()){
                case R.id.secure_remind_setting_first_layout:
                    firstLayoutListener();
                    break;
            }
        }

    }

    /**
     * 第一行的点击事件
     */
    private void firstLayoutListener(){
        //隐私与安全--修改密码
        if (type.equals("secure")){
            ((OnSecureRemindInterface)context).modifyPassword();
        }
        //提醒与通知
        else {

        }
    }

}
